//
//  FeedImgCollectionViewCell.m
//  fp
//
//  Created by xingshuai on 2020/11/11.
//

#import "FeedImgCollectionViewCell.h"

@interface FeedImgCollectionViewCell ()

@property (nonatomic, strong) UIImageView *img;
@property (nonatomic, strong) UIButton *del_btn;

@end

@implementation FeedImgCollectionViewCell

-(instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame])
    {
        self.img = [[UIImageView alloc]init];
        self.img.layer.cornerRadius = 4;
        self.img.layer.masksToBounds = YES;
        [self.contentView addSubview:self.img];
        [self.img mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.bottom.equalTo(self.contentView);
            make.top.equalTo(self.contentView).offset(10);
            make.right.equalTo(self.contentView).offset(-10);
        }];
        
        self.del_btn = [UIButton buttonWithType:UIButtonTypeCustom];
        self.del_btn.hidden = YES;
        self.del_btn.layer.cornerRadius = 10;
        self.del_btn.layer.masksToBounds = YES;
        [self.del_btn setTitle:@"X" forState:UIControlStateNormal];
        self.del_btn.titleLabel.font = [UIFont pingFangSCWithWeight:FontWeightStyleMedium size:14];
        [self.del_btn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
        [self.del_btn setBackgroundColor:[UIColor colorWithHexString:@"#000000" alpha:0.25]];
        [self.del_btn addTarget:self action:@selector(clickDel:) forControlEvents:UIControlEventTouchUpInside];
        [self.contentView addSubview:self.del_btn];
        [self.del_btn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.right.equalTo(self.contentView);
            make.width.mas_equalTo(20);
            make.height.mas_equalTo(20);
        }];
    }
    return self;
}

-(void)reloadCellImg:(UIImage *)imgStr index:(NSInteger)index totalCount:(NSInteger)totalCount {
    self.img.image = imgStr;
    if (index == totalCount-1) {
        UIImage *add_img = [UIImage imageNamed:@"feed_add"];
        if ([imgStr isEqual:add_img]) {
            self.del_btn.hidden = YES;
        } else {
            self.del_btn.hidden = NO;
        }
    } else {
        self.del_btn.hidden = NO;
    }
    
    self.del_btn.tag = index;
}

-(void)clickDel:(UIButton *)sender {
    if ([_delegate respondsToSelector:@selector(clickDelBtnButtonTag:)]) {
        [_delegate clickDelBtnButtonTag:sender.tag];
    }
}


@end
